
package org.springblade.common.tool;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * 通用工具类
 *
 * @author Chill
 */
public class CommonUtil {
	/**
	 * request payload形式在servlet中的获取方式
	 * @param req
	 * @return
	 */
	public static String getRequestPayload(HttpServletRequest req) {
		StringBuilder sb = new StringBuilder();
		try(BufferedReader reader = req.getReader();) {
			char[]buff = new char[1024];
			int len;
			while((len = reader.read(buff)) != -1) {
				sb.append(buff,0, len);
			}
		}catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString();
	}

}
